from gopigo import *	#Has the basic functions for controlling the GoPiGo Robot
import sys	#Used for closing the running program
import time, random, logging

logging.basicConfig(level=logging.DEBUG,
                    format='(%(threadName)-10s) %(message)s',
                    )
						
def search():
	while True:
		dist=us_dist(15)
		if dist < 20:
			logging.debug('Found it!')
			return True
		if dist < 100:
			logging.debug('Something is out there...')
			return False
		left_rot()
		time.sleep(.1)
		stop()
		dist=us_dist(15)
		if dist < 20:
			logging.debug('Found it!')
			return True
		if dist < 100:
			logging.debug('Something is out there...')
			return False
			
if __name__ == '__main__':
	stop()

	foundit = False;
	while not foundit:
		logging.debug('Searching...')
		foundit = search()
		fwd()
		time.sleep(.5)
	logging.debug('Done')
	
	stop()